/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ManualEntryForum.java
 *
 * Created on Nov 9, 2010, 10:57:27 PM
 */

/**
 *
 * @author Sujal
 */

import java.awt.BorderLayout;
import javax.swing.*;
import java.lang.Thread;
import java.lang.Runnable;
import java.util.Vector;
import java.lang.reflect.Array;
import java.util.HashSet;
import java.sql.SQLException;
import java.lang.Integer;
import java.lang.Math;

public class ManualEntryForum extends javax.swing.JDialog {

    private boolean saveData;
    /** Creates new form ManualEntryForum */
    public ManualEntryForum(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        saveData=false;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        SaveB = new javax.swing.JButton();
        CancelB = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        EventB = new javax.swing.JLabel();
        NameB = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        Score1 = new javax.swing.JLabel();
        ScoreText1 = new javax.swing.JTextField();
        Score2 = new javax.swing.JLabel();
        ScoreText2 = new javax.swing.JTextField();
        Score3 = new javax.swing.JLabel();
        ScoreText3 = new javax.swing.JTextField();
        Score4 = new javax.swing.JLabel();
        ScoreText4 = new javax.swing.JTextField();
        Score5 = new javax.swing.JLabel();
        ScoreText5 = new javax.swing.JTextField();
        ScoreText6 = new javax.swing.JTextField();
        Score6 = new javax.swing.JLabel();
        Score7 = new javax.swing.JLabel();
        ScoreText7 = new javax.swing.JTextField();
        Score8 = new javax.swing.JLabel();
        ScoreText8 = new javax.swing.JTextField();
        Score9 = new javax.swing.JLabel();
        ScoreText9 = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Manual Entry Forum");
        setAlwaysOnTop(true);
        setModal(true);
        setName("ManualEntryForum"); // NOI18N

        SaveB.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N
        SaveB.setText("Save");
        SaveB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SaveBActionPerformed(evt);
            }
        });

        CancelB.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N
        CancelB.setText("Cancel");
        CancelB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CancelBActionPerformed(evt);
            }
        });

        EventB.setFont(new java.awt.Font("Tahoma", 0, 24));
        EventB.setText("Event : ");

        NameB.setFont(new java.awt.Font("Tahoma", 0, 24));
        NameB.setText("Name : ");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(NameB)
                    .addComponent(EventB))
                .addContainerGap(972, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(EventB)
                .addGap(18, 18, 18)
                .addComponent(NameB)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        Score1.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N
        Score1.setText("Score 1");
        Score1.setFocusable(false);

        ScoreText1.setFont(new java.awt.Font("Tahoma", 0, 24));
        ScoreText1.setText("0.0");
        ScoreText1.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));

        Score2.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N
        Score2.setText("Score 2");

        ScoreText2.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N
        ScoreText2.setText("0.0");
        ScoreText2.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));

        Score3.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N
        Score3.setText("Score 3");

        ScoreText3.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N
        ScoreText3.setText("0.0");
        ScoreText3.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
        ScoreText3.setCursor(new java.awt.Cursor(java.awt.Cursor.TEXT_CURSOR));

        Score4.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N
        Score4.setText("Score 4");

        ScoreText4.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N
        ScoreText4.setText("0.0");
        ScoreText4.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));

        Score5.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N
        Score5.setText("Score 5");

        ScoreText5.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N
        ScoreText5.setText("0.0");
        ScoreText5.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));

        ScoreText6.setFont(new java.awt.Font("Tahoma", 0, 24));
        ScoreText6.setText("0.0");
        ScoreText6.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));

        Score6.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N
        Score6.setText("Score 6");

        Score7.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N
        Score7.setText("Score 7");

        ScoreText7.setFont(new java.awt.Font("Tahoma", 0, 24));
        ScoreText7.setText("0.0");
        ScoreText7.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));

        Score8.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N
        Score8.setText("Score 8");

        ScoreText8.setFont(new java.awt.Font("Tahoma", 0, 24));
        ScoreText8.setText("0.0");
        ScoreText8.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));

        Score9.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N
        Score9.setText("Score 9");

        ScoreText9.setFont(new java.awt.Font("Tahoma", 0, 24));
        ScoreText9.setText("0.0");
        ScoreText9.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
        ScoreText9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ScoreText9ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(83, 83, 83)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addGroup(jPanel2Layout.createSequentialGroup()
                            .addComponent(Score7)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addComponent(ScoreText7, javax.swing.GroupLayout.PREFERRED_SIZE, 163, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(jPanel2Layout.createSequentialGroup()
                            .addComponent(Score1)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addComponent(ScoreText1, javax.swing.GroupLayout.PREFERRED_SIZE, 163, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(Score4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(ScoreText4, javax.swing.GroupLayout.PREFERRED_SIZE, 163, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(77, 77, 77)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(Score8)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(ScoreText8, javax.swing.GroupLayout.PREFERRED_SIZE, 163, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 75, Short.MAX_VALUE)
                        .addComponent(Score9)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(ScoreText9, javax.swing.GroupLayout.PREFERRED_SIZE, 163, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(Score2)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(ScoreText2, javax.swing.GroupLayout.PREFERRED_SIZE, 163, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(Score5)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(ScoreText5, javax.swing.GroupLayout.PREFERRED_SIZE, 163, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(75, 75, 75)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(Score3)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(ScoreText3, javax.swing.GroupLayout.PREFERRED_SIZE, 163, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(Score6)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(ScoreText6, javax.swing.GroupLayout.PREFERRED_SIZE, 163, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addGap(155, 155, 155))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(61, 61, 61)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(ScoreText3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(Score3)
                    .addComponent(ScoreText2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(Score2)
                    .addComponent(ScoreText1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(Score1))
                .addGap(30, 30, 30)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(ScoreText4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(Score4)
                    .addComponent(ScoreText5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(Score5)
                    .addComponent(ScoreText6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(Score6))
                .addGap(28, 28, 28)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(ScoreText7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(Score7)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(ScoreText8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(Score9)
                        .addComponent(ScoreText9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(Score8))
                .addContainerGap(51, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(693, Short.MAX_VALUE)
                .addComponent(SaveB, javax.swing.GroupLayout.PREFERRED_SIZE, 151, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(51, 51, 51)
                .addComponent(CancelB)
                .addGap(83, 83, 83))
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(CancelB)
                    .addComponent(SaveB))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void SaveBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SaveBActionPerformed

        try
        {
            String value="";
            for(int index=0;index<9;index++)
            {
                switch(index)
                {
                    case 0:
                        value=ScoreText1.getText();
                        break;
                    case 1:
                        value=ScoreText2.getText();
                        break;
                    case 2:
                        value=ScoreText3.getText();
                        break;
                    case 3:
                        value=ScoreText4.getText();
                        break;
                    case 4:
                        value=ScoreText5.getText();
                        break;
                    case 5:
                        value=ScoreText6.getText();
                        break;
                    case 6:
                        value=ScoreText7.getText();
                        break;
                    case 7:
                        value=ScoreText8.getText();
                        break;
                    case 8:
                    default:
                        value=ScoreText9.getText();
                        break;
               }
               if(value.length()>0)
               {
                   float valueFloat = Float.parseFloat(value);

                   // bad score
                   if (valueFloat<0 || valueFloat>10)
                   {
                       JOptionPane.showMessageDialog(this, "Score out of range (0-10)" , "Error", JOptionPane.OK_CANCEL_OPTION);
                       return;
                   }
               }
            }
        } catch (NumberFormatException e)
        {
            JOptionPane.showMessageDialog(this, "Invalid character" , "Error", JOptionPane.OK_CANCEL_OPTION);
            return;
        }

        saveData=true;
        setVisible(false);
    }//GEN-LAST:event_SaveBActionPerformed

    private void CancelBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CancelBActionPerformed
        saveData=false;
        setVisible(false);
    }//GEN-LAST:event_CancelBActionPerformed

    private void ScoreText9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ScoreText9ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_ScoreText9ActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                ManualEntryForum dialog = new ManualEntryForum(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }

    public void setName(String name)
    {
        NameB.setText("Name : "+name);
    }

    public void setEvent(String event)
    {
        EventB.setText("Event : "+event);
    }

    public void setScore(int index,String data)
    {
        switch(index)
        {
            case 0:
                ScoreText1.setText(data);
                break;
            case 1:
                ScoreText2.setText(data);
                break;
            case 2:
                ScoreText3.setText(data);
                break;
            case 3:
                ScoreText4.setText(data);
                break;
            case 4:
                ScoreText5.setText(data);
                break;
            case 5:
                ScoreText6.setText(data);
                break;
            case 6:
                ScoreText7.setText(data);
                break;
            case 7:
                ScoreText8.setText(data);
                break;
            case 8:
            default:
                ScoreText9.setText(data);
                break;
       }
    }

    
     public String getJudgeString(int index)
    {
        String value="";
        switch(index)
        {
            case 0:
                value=ScoreText1.getText();
                break;
            case 1:
                value=ScoreText2.getText();
                break;
            case 2:
                value=ScoreText3.getText();
                break;
            case 3:
                value=ScoreText4.getText();
                break;
            case 4:
                value=ScoreText5.getText();
                break;
            case 5:
                value=ScoreText6.getText();
                break;
            case 6:
                value=ScoreText7.getText();
                break;
            case 7:
                value=ScoreText8.getText();
                break;
            case 8:
            default:
                value=ScoreText9.getText();
                break;
       };
        return value;
    }
    
    public float getScore(int index)
    {
        float valueFloat=0.0f;
        try
        {
            String value="";
            switch(index)
            {
                case 0:
                    value=ScoreText1.getText();
                    break;
                case 1:
                    value=ScoreText2.getText();
                    break;
                case 2:
                    value=ScoreText3.getText();
                    break;
                case 3:
                    value=ScoreText4.getText();
                    break;
                case 4:
                    value=ScoreText5.getText();
                    break;
                case 5:
                    value=ScoreText6.getText();
                    break;
                case 6:
                    value=ScoreText7.getText();
                    break;
                case 7:
                    value=ScoreText8.getText();
                    break;
                case 8:
                default:
                    value=ScoreText9.getText();
                    break;
           }
           if(value.length()>0)
           {
               valueFloat = Float.parseFloat(value);

               // bad score
               if (valueFloat<0 || valueFloat>10)
               {
                   JOptionPane.showMessageDialog(this, "Score out of range (0-10)" , "Error", JOptionPane.OK_CANCEL_OPTION);
                   return 0.0f;
               }
           }
        } catch (NumberFormatException e)
        {
            JOptionPane.showMessageDialog(this, "Invalid character" , "Error", JOptionPane.OK_CANCEL_OPTION);
            return 0.0f;
        }
        return valueFloat;
    }
    public boolean SaveClicked()
    {
        return saveData;
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton CancelB;
    private javax.swing.JLabel EventB;
    private javax.swing.JLabel NameB;
    private javax.swing.JButton SaveB;
    private javax.swing.JLabel Score1;
    private javax.swing.JLabel Score2;
    private javax.swing.JLabel Score3;
    private javax.swing.JLabel Score4;
    private javax.swing.JLabel Score5;
    private javax.swing.JLabel Score6;
    private javax.swing.JLabel Score7;
    private javax.swing.JLabel Score8;
    private javax.swing.JLabel Score9;
    private javax.swing.JTextField ScoreText1;
    private javax.swing.JTextField ScoreText2;
    private javax.swing.JTextField ScoreText3;
    private javax.swing.JTextField ScoreText4;
    private javax.swing.JTextField ScoreText5;
    private javax.swing.JTextField ScoreText6;
    private javax.swing.JTextField ScoreText7;
    private javax.swing.JTextField ScoreText8;
    private javax.swing.JTextField ScoreText9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    // End of variables declaration//GEN-END:variables

}
